{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "383b1cc6",
   "metadata": {},
   "source": [
    "# 通用场景识别"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bc81678e",
   "metadata": {},
   "source": [
    "## 通用文字识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "id": "dcccd300",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'refresh_token': '25.cae5829af7c1ad7b95d361e6b97432ab.315360000.1965042535.282335-25946565', 'expires_in': 2592000, 'session_key': '9mzdXUdSiz48rfl0sP5c6SMQN2gR1UwOOCa/0YQDwGKNS/ihTYDpEUJjxYm+VgUExX6IAQ+TGt2U/yZQkXhuc/l6ePSrig==', 'access_token': '24.f374634b76b80087bb8fdba14109fce2.2592000.1652274535.282335-25946565', 'scope': 'public vis-ocr_ocr brain_ocr_scope brain_ocr_general brain_ocr_general_basic vis-ocr_business_license brain_ocr_webimage brain_all_scope brain_ocr_idcard brain_ocr_driving_license brain_ocr_vehicle_license vis-ocr_plate_number brain_solution brain_ocr_plate_number brain_ocr_accurate brain_ocr_accurate_basic brain_ocr_receipt brain_ocr_business_license brain_solution_iocr brain_qrcode brain_ocr_handwriting brain_form brain_ocr_passport brain_ocr_vat_invoice brain_numbers brain_ocr_business_card brain_ocr_train_ticket brain_ocr_taxi_receipt vis-ocr_household_register vis-ocr_vis-classify_birth_certificate vis-ocr_台湾通行证 vis-ocr_港澳通行证 vis-ocr_机动车购车发票识别 vis-ocr_机动车检验合格证识别 vis-ocr_车辆vin码识别 vis-ocr_定额发票识别 vis-ocr_保单识别 vis-ocr_机打发票识别 vis-ocr_行程单识别 brain_ocr_vin brain_ocr_quota_invoice brain_ocr_birth_certificate brain_ocr_household_register brain_ocr_HK_Macau_pass brain_ocr_taiwan_pass brain_ocr_vehicle_invoice brain_ocr_vehicle_certificate brain_ocr_air_ticket brain_ocr_invoice brain_ocr_insurance_doc brain_formula brain_seal brain_ocr_facade brain_ocr_meter brain_doc_analysis brain_ocr_webimage_loc brain_ocr_medical_paper brain_ocr_doc_analysis_office brain_vat_invoice_verification brain_ocr_medical_detail brain_vehicle_registration_certificate brain_ocr_online_taxi_itinerary brain_ocr_multi_idcard brain_ocr_mixed_multi_vehicle brain_ocr_weigth_note brain_ocr_ multiple_invoice wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online', 'session_secret': '8bade3f6e26d5325d8f6bc228c17694c'}\n"
     ]
    }
   ],
   "source": [
    "import requests \n",
    "host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=PCP2HGeQhYQvmpXEkvQtVBkj&client_secret=pBWWyoVAm0zqpfXY61TY8yvUOEXFQ5SB'\n",
    "#准备URL参数\n",
    "payload = {\n",
    "    'grant_type':'client_credeials',\n",
    "    'client_id':'PCP2HGeQhYQvmpXEkvQtVBkj',\n",
    "    'client_secret':'pBWWyoVAm0zqpfXY61TY8yvUOEXFQ5SB'\n",
    "}\n",
    "response = requests.get(host)\n",
    "if response:\n",
    "    print(response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 149,
   "id": "06437153",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'24.f374634b76b80087bb8fdba14109fce2.2592000.1652274535.282335-25946565'"
      ]
     },
     "execution_count": 149,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "access_token1 = response.json()['access_token']\n",
    "access_token1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "id": "8dfb7a41",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'words_result': [{'words': 'La conquete des marches'}, {'words': \"Dans le cominerce international,ce n'est pas encore vraiment la guerre.\"}, {'words': 'Mais la guerilla se developpe et prend des proportions alarmantes.Sur les cinq'}, {'words': \"continents,les frontieres se herissent d'obstacles de toute sorte.Des procedes\"}, {'words': 'deloyaux sont employes pour arracher les gros contrats.On se bat au couteau2'}, {'words': 'pour vendre des tee-shirts,des cereales,des locomotives ou des usines clefs en'}, {'words': 'main.3'}, {'words': 'Pourtant,chaque fois que les dirigeants du monde occidental se rencontrent,'}, {'words': 'ils font le serment solennel de maintenir la liberte des echanges.Au sommet)'}, {'words': \"des pays (riches),au dernier conseil du Marche commun et a l'assemblee an-\"}, {'words': \"nuelle de 1'0.C.D.E.,les chefs de gouvernement et les ministres des Finances\"}, {'words': 'des grandes puissances industrielles ont promis de ne pas ceder a la tentation du'}, {'words': 'protectionnisme.5 Ils se sont meme engages a franchir une nouvelle etape du'}, {'words': 'desarmement douanier.'}, {'words': 'A peine rentres chez eux,ces memes dirigeants promulguent des mesures qui'}, {'words': 'sont en contradiction formelle avec leurs promesses.A cela une seule raison:6 la'}, {'words': \"reprise economique est tres lente a 1'echelle de la planete.En consequence,il y a\"}, {'words': \"plus de quinze millions de chomeurs sur les deux rives de l'Atlantique.Sous I'ef-\"}, {'words': 'fet de la concurrence (sauvage)des pays a bas salaire ou qui ont des charges so-'}, {'words': \"ciales et fiscales anormalement faibles,8 des branches entieres d'industrie sont en\"}, {'words': 'peril sur le vieux continent:siderurgie,constructions navales,textiles,chaus-'}, {'words': 'sures,composants electroniques,equipement,etc.Pour maintenir les carnets de'}, {'words': \"commandes et preserver 1'emploi,les organisations patronales et les syndicats,\"}], 'words_result_num': 23, 'log_id': 1513504739753496612}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "通用文字识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('fayu.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token=access_token1\n",
    "\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cbaed82a",
   "metadata": {},
   "source": [
    "## 网络图片文字识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "id": "c9caa110",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'words_result': [{'words': '鸿源華府'}, {'words': '耗作品质无忧'}, {'words': '2020.6.6'}, {'words': '全国爱眼日'}, {'words': 'm'}, {'words': '用'}, {'words': '眼睛'}, {'words': '观察世界'}, {'words': '关爱你的眼睛'}, {'words': '用心灵感受'}, {'words': '生活'}, {'words': '567-88881'}, {'words': '资讯中心:浦东新区灵韵大厦666'}, {'words': '本图文广告仅供示意参考,请以政府审批文件及合同要约为准'}], 'words_result_num': 14, 'log_id': 1513505776987191009}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "网络图片文字识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/ocr/v1/webimage\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('wangtu.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token=access_token1\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7c1556f8",
   "metadata": {},
   "source": [
    "## 二维码识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 164,
   "id": "18174632",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'codes_result': [], 'codes_result_num': 0, 'log_id': 1513506008595461842}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "网络图片文字识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/ocr/v1/qrcode\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('qr.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token=access_token1\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "925590bc",
   "metadata": {},
   "source": [
    "# 卡证文字识别"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "75610475",
   "metadata": {},
   "source": [
    "## 身份证或银行卡识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 173,
   "id": "8b159d9b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'log_id': 1513507429538260200, 'error_msg': 'missing required parameter(s)', 'error_code': 282003}\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "身份证识别\n",
    "'''\n",
    "\n",
    "request_url = \"https://aip.baidubce.com/rest/2.0/ocr/v1/idcard\"\n",
    "# 二进制方式打开图片文件\n",
    "f = open('02.jpeg', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "\n",
    "params = {\"image\":img}\n",
    "access_token=access_token1\n",
    "request_url = request_url + \"?access_token=\" + access_token\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=params, headers=headers)\n",
    "if response:\n",
    "    print (response.json())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "741c0500",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dfc5b7c0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "53e2af60",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
